<?php
  session_start();
  include_once 'class_projekt.php';
  include_once 'lang/german.php';
?>

<html>
  <head>
    <title><?php echo $lang_title;  ?></title>
    <script type="text/javascript" src="js/jquery-1.7.1.js"></script>
    <script type="text/javascript" src="js/like.js"></script>
    <script type="text/javascript">
      function unhide(divID) {
      var item = document.getElementById(divID);
      if (item) {item.className=(item.className=='hidden')?'unhidden':'hidden';} }
    </script>
    <script type="text/javascript" src="js/fontsize.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  </head>

  <body>
  
  <div id="menu">
      
      <div id="header">
        <img src="graphics/header.png" />
      </div>
      
      <div id="language_button">
        <a href="javascript:unhide('language_selection');"><img src="graphics/flag_uk.png" style="border: none; float: left;"/></a>
      </div>
      
      <div id="authorization_buttons">
        <a href="javascript:unhide('login');">
          <div id="login_button" style="width:200px">
            Login
          </div>
        </a>
        <a href="javascript:unhide('register');">
          <div id="register_button" style="width:200px">
            Register
          </div>
        </a>
      
      <div id="admin_center" style="width:200px">
        <?php
          if ($_SESSION['auth_username'])
          {
			if ($_SESSION['auth_level'] > 1)
			{
            echo '<a href="admin/admin.php">'.$lang_admin.'</a> ';
			}
			echo'<a href="logout.php">'.$lang_logout .'</a> <br /> ';
            echo $lang_hello . " ";
            echo $_SESSION['auth_username'];
            echo '<br/>';
          }
        ?>
      </div>
      </div>
      <div id="project_selection">
        <?php echo $lang_proj; ?>
        <form action="index.php" method="post">
          <?php $projekt = new Projekt;?>
          <select name="proj">
            <?php $projekt->pros(); ?>
          </select>
          <select name="lang">
            <?php $projekt->lang(); ?>
          </select>
          <input type="submit" name="projekt" value="<?php echo $lang_button_proj; ?>"> 
        </form>
      </div>
      
  </div>
  
  <div id="submenu">
  
    <div id="authorization_forms">
        <div id="login" class="hidden">
          <?php echo $lang_login; ?>
          <form action="login.php" method="post">
            <label><?php echo $lang_username; ?></label> <input type="text" name="user"><br/>
            <label><?php echo $lang_password; ?></label> <input type="password" name="password"><br/>
            <input type="submit" name="login" value="<?php echo $lang_button_login; ?>">
          </form>
        </div>
        <div id="register" class="hidden">
          <?php echo $lang_register; ?>
          <form action="index.php" method="post">
            <label><?php echo $lang_username; ?>:</label> <input type="text" name="user"><br/>
            <label><?php echo $lang_password; ?>:</label><input type="password" name="password"><br/>
            <label><?php echo $lang_password2; ?>: </label><input type="password" name="password2"><br/>
            <label><?php echo $lang_mail; ?>:</label> <input type="email" name="email"><br/>
            <input type="submit" name="register" value="<?php echo $lang_register_button; ?>">
          </form>
        </div>
    </div>

    <div id="language_selection" class="hidden">
        <img src="graphics/flag_at.png" />
        <img src="graphics/flag_it.png" />
        <img src="graphics/flag_fr.png" />
        <img src="graphics/flag_ch.png" />
    </div>
  </div>


  <div id="translation">

<?php

  if ($_POST['register'])
  {
    include_once 'class_register.php';
    $register = new Register;

    $register->data($_POST['user'],$_POST['password'],$_POST['password2'], $_POST['email']);
    $go = $register->controll();
    if ($go == true)
    {
      $register->insert();
    }
  }

  if ($_GET['error'] == 1)
  {
    echo $lang_login_error;
  }

  if ($_POST['projekt'])
  {
    $proj = $_POST['proj'];
    $lang = $_POST['lang']; 

    if ($_POST['hinzu'])
    {
      $new = $_POST['new'];
      $word_id = $_POST['word_id'];
      
      if ($projekt->newWord($word_id,$new) == false)
      {
        echo $lang_word_error;
      }
    }

    if ($projekt->getTable($proj, $lang) == true)
    {

?>
      <table border=1>
        <th><?php echo $lang_table_derzeit; ?></th>
        <th><?php echo $lang_table_vorschlag; ?></th>
        <th><?php echo $lang_table_new_vorschlag; ?></th>
<?php
        $projekt->getNames($proj,$lang,$_SESSION['auth_username']);
?>
      </table>

<?php
    }  
    else 
    {
      echo $lang_table_error;
    }
  }
?>
  </div>
  
  </body>
</html>
